package controllers;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterSuite;

import model.*;
import daos.*;


public class AssignDesiredHoursController {

	private ApplicationContext applicationContext;

	public void assignTimeSlots(ArrayList<String> listDays, ArrayList<Integer> listHourStart, ArrayList<Integer> listHourEnd, int studentId) 
	{
		
applicationContext = new ClassPathXmlApplicationContext(new String[] {"classpath:persistenceTest/applicationContext.xml"});
		
		StudentProfileDAO	sProfileDAO = (StudentProfileDAO)applicationContext.getBean("studentProfileDAO");
		StudentProfile selectedStudent= sProfileDAO.findStudentById(studentId);
		
		TimeSlotDAO tsDAO = (TimeSlotDAO)applicationContext.getBean("timeSlotDAO");	
		
		List<TimeSlot> tsList= new ArrayList<TimeSlot>();
		
		for(int i=0; i< listDays.size() ; i++)
		{
			TimeSlot ts = new TimeSlot(listDays.get(i),listHourStart.get(i),listHourEnd.get(i));
			tsDAO.save(ts);
			tsList.add(ts);						
		}
				
		selectedStudent.setDesiredHours(tsList);
		
		sProfileDAO.save(selectedStudent);
	}
}

